<?php
//daftar_hotel.php

require_once 'config/config.php';
require_once 'lib/member.php';
require_once 'lib/user.php';
require_once 'lib/kelas.php';
require_once 'lib/produk.php';

$config=new config();
$config->connect();

$Cur_page=1;
$per_page=10;
if(!ISSET($_GET['id_kelas'])){
	$Member_Dao=new Member_Dao();
	$data2=$Member_Dao->get_all();
	//var_dump($data);
	$Page_num = ceil(count($data2)/$per_page);
	$dataplus = $Page_num * $per_page ;
	$datasel = count($data2) - $per_page * ($Page_num - 1);
	
	//echo $Page_num;
	
	if(isset($_GET['page'])){
	$Cur_page = $_GET['page'];
		if( $Cur_page >$Page_num){
			$Cur_page=$Page_num;
			
		}
		if( $Cur_page < 1 ){
			$Cur_page = 1;
		}
	} 
	
	if($datasel>0 && $Cur_page==$Page_num){
		
		$data = array_slice($data2,$per_page * ($Cur_page -1));
		//var_dump($data);
		
		} else {$data = array_slice($data2,$Cur_page, $per_page);}
	//var_dump($data);
	
}

if(ISSET($_GET['id_kelas'])){
	//echo "2";
	$Member_Dao=new Member_Dao();
	$data2=$Member_Dao->get_kelas($_GET['id_kelas']);
	
	
	
	$Page_num = ceil(count($data2)/$per_page);
	$dataplus = $Page_num * $per_page ;
	$datasel = count($data2) - $per_page * ($Page_num - 1);
	
	//echo $Page_num;
	
	if(isset($_GET['page'])){
	$Cur_page = $_GET['page'];
		if( $Cur_page >$Page_num){
			$Cur_page=$Page_num;
			
		}
		if( $Cur_page < 1 ){
			$Cur_page = 1;
		}
	} 
	
	if($datasel>0 && $Cur_page==$Page_num){
		
		$data = array_slice($data2,$per_page * ($Cur_page -1));
		//var_dump($data);
		
		} else {$data = array_slice($data2,$Cur_page, $per_page);}
	//var_dump($data);
}

$Kelas_Dao=new Kelas_Dao();
$kelas=$Kelas_Dao->get_all();

?>
<?php include("header.php") ?>
<?php // include("menu_kiri.php") ?>
<dl id="browse">
             <?php include("menu_kiri.php") ?>           
			  <dl id="browse">
			  <dt>Kategori Kelas</dt>
			  <dd><a href="daftar_hotel.php">Semua</a></dd>
			  <?php foreach($kelas as $Kelas){ ?>
              <dd><?php echo "<a href=\"daftar_hotel.php?id_kelas=$Kelas->id_kelas\">".ucwords($Kelas->kelas)."</a>";?></dd>
			  <?php } ?>
              <br></br>
			  </dl>
              
        
</dl>
          

<div id="body">
  
<div class="topbox">
<?php
	$i=1;
	foreach($data as $member){
	echo "<div class=\"leftbox2\">"; 
	echo "<table border=0 cellspacing=0 cellpadding=3>";
	$User_Dao=new User_Dao();
	$user=$User_Dao->get_id($member->id);
	//echo $member->id;
	$Kelas_Dao=new Kelas_Dao();
	$kelas=$Kelas_Dao->get_id($member->id_kelas);
	$Produk_Dao=new Produk_Dao();
	$minprice=$Produk_Dao->get_minprice($member->id);
	$maxprice=$Produk_Dao->get_maxprice($member->id);
	
	echo "<tr>";
		echo "<td>";
			if($member->foto_member!=""){
			echo "<a href=\"detil_hotel.php?id=$member->id\"><image src=\"member/images/hotel/$member->foto_member\" 
			width=\"160\" height=\"141\"></a>";
			} else { echo "<image src=\"images/hotel_1.png\" width=\"160\" height=\"141\">";}
			echo "</td>";
	
		echo "<td class=\"topleft\">";
			echo "<p><b><a href=\"detil_hotel.php?id=$member->id\">Hotel ".ucwords($member->nama)."</a> , ".ucwords($kelas->kelas)."</b></p>";
			echo "<p>Kisaran harga: Rp".number_format($minprice, 2, '.', ',')." - "."Rp".number_format($maxprice, 2, '.', ',')."</p>";
			echo "<p>Email: ".$user->email."</p>";
			echo "<p>Alamat: ".$member->alamat."</p>";
			echo "<p>no_telp: ".$member->no_telp."</p>";
			echo "<p>Fasilitas: ".$member->fasilitas_umum."</p>";
		echo "</td>";
	echo "</tr>";

 $i++;
 echo "</table>";
 echo "</div>";
 }?> 
 
</div> 

<div class="topbox">
<?php if(isset($_GET['id_kelas']) && $Page_num>0) { 
$kelas = $_GET['id_kelas'];
?>
	
	<?php echo "Halaman ".$Cur_page." dari ".$Page_num."<br/>";?>
	<?php echo  "<a href='".$_SERVER['PHP_SELF']."?id_kelas=".$kelas."&&page=".(1)."'>First  </a>";?>
	<?php echo  "<a href='".$_SERVER['PHP_SELF']."?id_kelas=".$kelas."&&page=".($Cur_page -1)."'>Prev  </a>";?>
	<?php echo "<a href='".$_SERVER['PHP_SELF']."?id_kelas=".$kelas."&&page=".($Cur_page+1)."'>Next  </a>";?>
	<?php echo  "<a href='".$_SERVER['PHP_SELF']."?id_kelas=".$kelas."&&page=".($Page_num)."'>Last</a>";?>
<?php }?>

<?php 
if(!isset($_GET['id_kelas']) && $Page_num>0){ ?>

<?php echo "Halaman ".$Cur_page." dari ".$Page_num."<br/>";?>
<?php echo  "<a href='".$_SERVER['PHP_SELF']."?page=".(1)."'>First  </a>";?>
<?php echo  "<a href='".$_SERVER['PHP_SELF']."?page=".($Cur_page -1)."'>Prev  </a>";?>
<?php echo "<a href='".$_SERVER['PHP_SELF']."?page=".($Cur_page+1)."'>Next  </a>";?>
<?php echo  "<a href='".$_SERVER['PHP_SELF']."?page=".($Page_num)."'>Last</a>";?>
<?php }?>

<?php
	if($Page_num==0){
		echo "Data tidak tersedia.";
	}

?>

</div>


</div>
          
         <div class="clear"></div>
         <?php include("footer.php") ?>
		